﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace DrivingCRM.Views.Private.CRM
{
    public partial class ListStakeholders : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
                if ((Session["User"] as List<string>)[0] == "Salesman" || (Session["User"] as List<string>)[0] == "Stakeholder")
                {
                    this.DS_Agencies.Where = "it.IdAgency == @CurrentAgency";
                    this.DS_Agencies.WhereParameters.Add(new Parameter() { DbType = System.Data.DbType.Int32, Name = "CurrentAgency", DefaultValue = (Session["User"] as List<string>)[2] });
                    this.DDL_Agencies.Enabled = false;
                }
                else if ((Session["User"] as List<string>)[0] == "Client")
                    Response.Redirect("~/Views/Default.aspx");
                else
                {
                    this.DDL_Agencies.Enabled = true;
                }

                if ((Session["User"] as List<string>)[0] == "Stakeholder")
                {
                    MembershipUser u = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                    Guid StaId = ((Guid)u.ProviderUserKey);

                    this.DS_Stakeholder.Where = "it.AgencyIdAgency == @IdAgency && it.Id == @IdStakeholder";
                    this.DS_Stakeholder.WhereParameters.Add(new Parameter() { DbType = System.Data.DbType.Guid, Name = "IdStakeholder", DefaultValue = StaId.ToString() });
                }
            }
            else
            {
                Response.Redirect("~/Views/Login.aspx");
            }
        }
    }
}